﻿using System;
using Microsoft.Extensions.Configuration;
using Snowflake.Net;

namespace Common.Helper
{
    public static class IdWorkerHelper
    {
        private static IConfiguration _configuration;

        private static IdWorker _idWorker;

        public static void Initialize(IConfiguration configuration)
        {
            _configuration ??= configuration ?? throw new ArgumentNullException(nameof(configuration));
            var workerId = _configuration.GetValue<long>("Snowflake:WorkerId");
            var datacenterId = _configuration.GetValue<long>("Snowflake:DatacenterId");
            _idWorker ??= new IdWorker(workerId, datacenterId);
        }

        public static long NextId()
        {
            return _idWorker.NextId();
        }
    }
}